package com.dhl.cloud.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dhl.cloud.common.Constants;
import com.dhl.cloud.common.http.HttpResult;
import com.dhl.cloud.common.http.HttpUser;
import com.dhl.cloud.common.vo.ComFrontBean;
import com.dhl.cloud.course.entity.MyPlan;
import com.dhl.cloud.course.service.MyPlanService;

@RestController
@RequestMapping(value = "/user")
public class MyPlanController extends BaseController{

	@Autowired
	private MyPlanService myPlanService;
	
    /**
     * 获取我的MyPlan列表
     */
    @GetMapping("getMyPlanList")
    public HttpResult getMyPlanList(HttpServletRequest request)
    {
    	HttpUser user = getUser(request);
        String username = user.getUsername();
        List<MyPlan> list = myPlanService.getMyPlanList(username);
        return HttpResult.success("",list);
    }
    
    @PostMapping("deleteMyPlan")
    public HttpResult deleteMyPlan(@RequestBody ComFrontBean ComFrontBean,HttpServletRequest request)
    {
        int flag = myPlanService.deleteByPrimaryKey(ComFrontBean.getId());
        return flag==1 ? HttpResult.success("删除成功"):HttpResult.error(Constants.ERROR_MSG_25);
    }
    
    @PostMapping("saveMyPlan")
    public HttpResult saveMyPlan(@RequestBody MyPlan myPlan,HttpServletRequest request)
    {
    	HttpUser user = getUser(request);
        String username = user.getUsername();
        myPlan.setUsername(username);
        int flag = myPlanService.insert(myPlan);
        return flag==1 ? HttpResult.success("操作成功"):HttpResult.error(Constants.ERROR_MSG_25);
    }
}
